<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function find(nums) {
      //有一个元素重复  nums是无序的
      //新建一个数组
      var arr = new Array(nums.length).fill(0);
      let res1 = 0, res2 = 0;
      for (let i of nums) {
        arr[i - 1]++;
        if (arr[i - 1] == 2) res1 = i;
      }
      for (let i = 0; i < arr.length; ++i) {
        if (arr[i] == 0) {
          return [res1, i + 1];
        }
      }
      return [];
    };
    console.log(find([1, 2, 2, 4]));
  </script>
</body>

</html>